home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / starcrus.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  14KB  |  600 lines

  1.  
  2. /* Ramtek - Star Cruiser */
  3.  
  4. #include "driver.h"
  5. #include "vidhrdw/generic.h"
  6.  
  7. static struct osd_bitmap *ship1_vid;
  8. static struct osd_bitmap *ship2_vid;
  9. static struct osd_bitmap *proj1_vid;
  10. static struct osd_bitmap *proj2_vid;
  11.  
  12. static int s1_x = 0;
  13. static int s1_y = 0;
  14. static int s2_x = 0;
  15. static int s2_y = 0;
  16. static int p1_x = 0;
  17. static int p1_y = 0;
  18. static int p2_x = 0;
  19. static int p2_y = 0;
  20.  
  21. static int p1_sprite = 0;
  22. static int p2_sprite = 0;
  23. static int s1_sprite = 0;
  24. static int s2_sprite = 0;
  25.  
  26. static int engine1_on = 0;
  27. static int engine2_on = 0;
  28. static int explode1_on = 0;
  29. static int explode2_on = 0;
  30. static int launch1_on = 0;
  31. static int launch2_on = 0;
  32.  
  33. /* The collision detection techniques use in this driver
  34.    are well explained in the comments in the sprint2 driver */
  35.  
  36. static int collision_reg = 0x00;
  37.  
  38. /* I hate to have sound in vidhrdw, but the sprite and
  39.    audio bits are in the same bytes, and there are so few
  40.    samples... */
  41.  
  42. int starcrus_engine_sound_playing = 0;
  43. int starcrus_explode_sound_playing = 0;
  44. int starcrus_launch1_sound_playing = 0;
  45. int starcrus_launch2_sound_playing = 0;
  46.  
  47. WRITE_HANDLER( starcrus_s1_x_w ) { s1_x = data^0xff; }
  48. WRITE_HANDLER( starcrus_s1_y_w ) { s1_y = data^0xff; }
  49. WRITE_HANDLER( starcrus_s2_x_w ) { s2_x = data^0xff; }
  50. WRITE_HANDLER( starcrus_s2_y_w ) { s2_y = data^0xff; }
  51. WRITE_HANDLER( starcrus_p1_x_w ) { p1_x = data^0xff; }
  52. WRITE_HANDLER( starcrus_p1_y_w ) { p1_y = data^0xff; }
  53. WRITE_HANDLER( starcrus_p2_x_w ) { p2_x = data^0xff; }
  54. WRITE_HANDLER( starcrus_p2_y_w ) { p2_y = data^0xff; }
  55.  
  56. int starcrus_vh_start(void)
  57. {
  58.     if ((ship1_vid = osd_create_bitmap(16,16)) == 0)
  59.     {
  60.         return 1;
  61.     }
  62.  
  63.     if ((ship2_vid = osd_create_bitmap(16,16)) == 0)
  64.     {
  65.         osd_free_bitmap(ship1_vid);
  66.         return 1;
  67.     }
  68.  
  69.     if ((proj1_vid = osd_create_bitmap(16,16)) == 0)
  70.     {
  71.         osd_free_bitmap(ship1_vid);
  72.         osd_free_bitmap(ship2_vid);
  73.         return 1;
  74.     }
  75.  
  76.     if ((proj2_vid = osd_create_bitmap(16,16)) == 0)
  77.     {
  78.         osd_free_bitmap(ship1_vid);
  79.         osd_free_bitmap(ship2_vid);
  80.         osd_free_bitmap(proj1_vid);
  81.         return 1;
  82.     }
  83.  
  84.     return 0;
  85. }
  86.  
  87. void starcrus_vh_stop(void)
  88. {
  89.     osd_free_bitmap(ship1_vid);
  90.     osd_free_bitmap(ship2_vid);
  91.     osd_free_bitmap(proj1_vid);
  92.     osd_free_bitmap(proj2_vid);
  93. }
  94.  
  95. WRITE_HANDLER( starcrus_ship_parm_1_w )
  96. {
  97.     s1_sprite = data&0x1f;
  98.     engine1_on = ((data&0x20)>>5)^0x01;
  99.  
  100.     if (engine1_on || engine2_on)
  101.     {
  102.         if (starcrus_engine_sound_playing == 0)
  103.         {
  104.             starcrus_engine_sound_playing = 1;
  105.             sample_start(0,0,1);    /* engine sample */
  106.  
  107.         }
  108.     }
  109.     else
  110.     {
  111.         if (starcrus_engine_sound_playing == 1)
  112.         {
  113.             starcrus_engine_sound_playing = 0;
  114.             sample_stop(0);
  115.         }
  116.     }
  117. }
  118.  
  119. WRITE_HANDLER( starcrus_ship_parm_2_w )
  120. {
  121.     s2_sprite = data&0x1f;
  122.     osd_led_w(2, ((data&0x80)>>7)^0x01);         /* game over lamp */
  123.     coin_counter_w(0, ((data&0x40)>>6)^0x01);     /* coin counter */
  124.     engine2_on = ((data&0x20)>>5)^0x01;
  125.  
  126.     if (engine1_on || engine2_on)
  127.     {
  128.         if (starcrus_engine_sound_playing == 0)
  129.         {
  130.             starcrus_engine_sound_playing = 1;
  131.             sample_start(0,0,1);    /* engine sample */
  132.         }
  133.     }
  134.     else
  135.     {
  136.         if (starcrus_engine_sound_playing == 1)
  137.         {
  138.             starcrus_engine_sound_playing = 0;
  139.             sample_stop(0);
  140.         }
  141.     }
  142.  
  143. }
  144.  
  145. WRITE_HANDLER( starcrus_proj_parm_1_w )
  146. {
  147.     p1_sprite = data&0x0f;
  148.     launch1_on = ((data&0x20)>>5)^0x01;
  149.     explode1_on = ((data&0x10)>>4)^0x01;
  150.  
  151.     if (explode1_on || explode2_on)
  152.     {
  153.         if (starcrus_explode_sound_playing == 0)
  154.         {
  155.             starcrus_explode_sound_playing = 1;
  156.             sample_start(1,1,1);    /* explosion initial sample */
  157.         }
  158.     }
  159.     else
  160.     {
  161.         if (starcrus_explode_sound_playing == 1)
  162.         {
  163.             starcrus_explode_sound_playing = 0;
  164.             sample_start(1,2,0);    /* explosion ending sample */
  165.         }
  166.     }
  167.  
  168.     if (launch1_on)
  169.     {
  170.         if (starcrus_launch1_sound_playing == 0)
  171.         {
  172.             starcrus_launch1_sound_playing = 1;
  173.             sample_start(2,3,0);    /* launch sample */
  174.         }
  175.     }
  176.     else
  177.     {
  178.         starcrus_launch1_sound_playing = 0;
  179.     }
  180. }
  181.  
  182. WRITE_HANDLER( starcrus_proj_parm_2_w )
  183. {
  184.     p2_sprite = data&0x0f;
  185.     launch2_on = ((data&0x20)>>5)^0x01;
  186.     explode2_on = ((data&0x10)>>4)^0x01;
  187.  
  188.     if (explode1_on || explode2_on)
  189.     {
  190.         if (starcrus_explode_sound_playing == 0)
  191.         {
  192.             starcrus_explode_sound_playing = 1;
  193.             sample_start(1,1,1);    /* explosion initial sample */
  194.         }
  195.     }
  196.     else
  197.     {
  198.         if (starcrus_explode_sound_playing == 1)
  199.         {
  200.             starcrus_explode_sound_playing = 0;
  201.             sample_start(1,2,0);    /* explosion ending sample */
  202.         }
  203.     }
  204.  
  205.     if (launch2_on)
  206.     {
  207.         if (starcrus_launch2_sound_playing == 0)
  208.         {
  209.             starcrus_launch2_sound_playing = 1;
  210.             sample_start(3,3,0);    /* launch sample */
  211.         }
  212.     }
  213.     else
  214.     {
  215.         starcrus_launch2_sound_playing = 0;
  216.     }
  217. }
  218.  
  219. int starcrus_collision_check_s1s2(void)
  220. {
  221.     int org_x, org_y;
  222.     int sx, sy;
  223.     struct rectangle clip;
  224.  
  225.     clip.min_x=0;
  226.     clip.max_x=15;
  227.     clip.min_y=0;
  228.     clip.max_y=15;
  229.  
  230.     fillbitmap(ship1_vid,Machine->pens[0],&clip);
  231.     fillbitmap(ship2_vid,Machine->pens[0],&clip);
  232.  
  233.     /* origin is with respect to ship1 */
  234.  
  235.     org_x = s1_x;
  236.     org_y = s1_y;
  237.  
  238.     /* Draw ship 1 */
  239.     drawgfx(ship1_vid,
  240.             Machine->gfx[8+((s1_sprite&0x04)>>2)],
  241.             (s1_sprite&0x03)^0x03,
  242.             0,
  243.             (s1_sprite&0x08)>>3,(s1_sprite&0x10)>>4,
  244.             s1_x-org_x,s1_y-org_y,
  245.             &clip,
  246.             TRANSPARENCY_NONE,
  247.             0);
  248.  
  249.     /* Draw ship 2 */
  250.     drawgfx(ship2_vid,
  251.             Machine->gfx[10+((s2_sprite&0x04)>>2)],
  252.             (s2_sprite&0x03)^0x03,
  253.             0,
  254.             (s2_sprite&0x08)>>3,(s2_sprite&0x10)>>4,
  255.             s2_x-org_x,s2_y-org_y,
  256.             &clip,
  257.             TRANSPARENCY_NONE,
  258.             0);
  259.  
  260.     /* Now check for collisions */
  261.     for (sy=0;sy<16;sy++)
  262.     {
  263.         for (sx=0;sx<16;sx++)
  264.         {
  265.             if (read_pixel(ship1_vid, sx, sy)==Machine->pens[1])
  266.                {
  267.                 /* Condition 1 - ship 1 = ship 2 */
  268.                 if (read_pixel(ship2_vid, sx, sy)==Machine->pens[1])
  269.                     return 1;
  270.             }
  271.         }
  272.     }
  273.  
  274.     return 0;
  275. }
  276.  
  277. int starcrus_collision_check_p1p2(void)
  278. {
  279.     int org_x, org_y;
  280.     int sx, sy;
  281.     struct rectangle clip;
  282.  
  283.     /* if both are scores, return */
  284.     if ( ((p1_sprite & 0x08) == 0) &&
  285.          ((p2_sprite & 0x08) == 0) )
  286.     {
  287.         return 0;
  288.     }
  289.  
  290.     clip.min_x=0;
  291.     clip.max_x=15;
  292.     clip.min_y=0;
  293.     clip.max_y=15;
  294.  
  295.     fillbitmap(proj1_vid,Machine->pens[0],&clip);
  296.     fillbitmap(proj2_vid,Machine->pens[0],&clip);
  297.  
  298.     /* origin is with respect to proj1 */
  299.  
  300.     org_x = p1_x;
  301.     org_y = p1_y;
  302.  
  303.     if (p1_sprite & 0x08)    /* if p1 is a projectile */
  304.     {
  305.         /* Draw score/projectile 1 */
  306.         drawgfx(proj1_vid,
  307.                 Machine->gfx[(p1_sprite&0x0c)>>2],
  308.                 (p1_sprite&0x03)^0x03,
  309.                 0,
  310.                 0,0,
  311.                 p1_x-org_x,p1_y-org_y,
  312.                 &clip,
  313.                 TRANSPARENCY_NONE,
  314.                 0);
  315.     }
  316.  
  317.     if (p2_sprite & 0x08)    /* if p2 is a projectile */
  318.     {
  319.         /* Draw score/projectile 2 */
  320.         drawgfx(proj2_vid,
  321.                 Machine->gfx[4+((p2_sprite&0x0c)>>2)],
  322.                 (p2_sprite&0x03)^0x03,
  323.                 0,
  324.                 0,0,
  325.                 p2_x-org_x,p2_y-org_y,
  326.                 &clip,
  327.                 TRANSPARENCY_NONE,
  328.                 0);
  329.     }
  330.  
  331.     /* Now check for collisions */
  332.     for (sy=0;sy<16;sy++)
  333.     {
  334.         for (sx=0;sx<16;sx++)
  335.         {
  336.             if (read_pixel(proj1_vid, sx, sy)==Machine->pens[1])
  337.                {
  338.                 /* Condition 1 - proj 1 = proj 2 */
  339.                 if (read_pixel(proj2_vid, sx, sy)==Machine->pens[1])
  340.                     return 1;
  341.             }
  342.         }
  343.     }
  344.  
  345.     return 0;
  346. }
  347.  
  348. int starcrus_collision_check_s1p1p2(void)
  349. {
  350.     int org_x, org_y;
  351.     int sx, sy;
  352.     struct rectangle clip;
  353.  
  354.     /* if both are scores, return */
  355.     if ( ((p1_sprite & 0x08) == 0) &&
  356.          ((p2_sprite & 0x08) == 0) )
  357.     {
  358.         return 0;
  359.     }
  360.  
  361.     clip.min_x=0;
  362.     clip.max_x=15;
  363.     clip.min_y=0;
  364.     clip.max_y=15;
  365.  
  366.     fillbitmap(ship1_vid,Machine->pens[0],&clip);
  367.     fillbitmap(proj1_vid,Machine->pens[0],&clip);
  368.     fillbitmap(proj2_vid,Machine->pens[0],&clip);
  369.  
  370.     /* origin is with respect to ship1 */
  371.  
  372.     org_x = s1_x;
  373.     org_y = s1_y;
  374.  
  375.     /* Draw ship 1 */
  376.     drawgfx(ship1_vid,
  377.             Machine->gfx[8+((s1_sprite&0x04)>>2)],
  378.             (s1_sprite&0x03)^0x03,
  379.             0,
  380.             (s1_sprite&0x08)>>3,(s1_sprite&0x10)>>4,
  381.             s1_x-org_x,s1_y-org_y,
  382.             &clip,
  383.             TRANSPARENCY_NONE,
  384.             0);
  385.  
  386.     if (p1_sprite & 0x08)    /* if p1 is a projectile */
  387.     {
  388.         /* Draw projectile 1 */
  389.         drawgfx(proj1_vid,
  390.                 Machine->gfx[(p1_sprite&0x0c)>>2],
  391.                 (p1_sprite&0x03)^0x03,
  392.                 0,
  393.                 0,0,
  394.                 p1_x-org_x,p1_y-org_y,
  395.                 &clip,
  396.                 TRANSPARENCY_NONE,
  397.                 0);
  398.     }
  399.  
  400.     if (p2_sprite & 0x08)    /* if p2 is a projectile */
  401.     {
  402.         /* Draw projectile 2 */
  403.         drawgfx(proj2_vid,
  404.                 Machine->gfx[4+((p2_sprite&0x0c)>>2)],
  405.                 (p2_sprite&0x03)^0x03,
  406.                 0,
  407.                 0,0,
  408.                 p2_x-org_x,p2_y-org_y,
  409.                 &clip,
  410.                 TRANSPARENCY_NONE,
  411.                 0);
  412.     }
  413.  
  414.     /* Now check for collisions */
  415.     for (sy=0;sy<16;sy++)
  416.     {
  417.         for (sx=0;sx<16;sx++)
  418.         {
  419.             if (read_pixel(ship1_vid, sx, sy)==Machine->pens[1])
  420.                {
  421.                 /* Condition 1 - ship 1 = proj 1 */
  422.                 if (read_pixel(proj1_vid, sx, sy)==Machine->pens[1])
  423.                     return 1;
  424.                 /* Condition 2 - ship 1 = proj 2 */
  425.                 if (read_pixel(proj2_vid, sx, sy)==Machine->pens[1])
  426.                     return 1;
  427.             }
  428.         }
  429.     }
  430.  
  431.     return 0;
  432. }
  433.  
  434. int starcrus_collision_check_s2p1p2(void)
  435. {
  436.     int org_x, org_y;
  437.     int sx, sy;
  438.     struct rectangle clip;
  439.  
  440.     /* if both are scores, return */
  441.     if ( ((p1_sprite & 0x08) == 0) &&
  442.          ((p2_sprite & 0x08) == 0) )
  443.     {
  444.         return 0;
  445.     }
  446.  
  447.     clip.min_x=0;
  448.     clip.max_x=15;
  449.     clip.min_y=0;
  450.     clip.max_y=15;
  451.  
  452.     fillbitmap(ship2_vid,Machine->pens[0],&clip);
  453.     fillbitmap(proj1_vid,Machine->pens[0],&clip);
  454.     fillbitmap(proj2_vid,Machine->pens[0],&clip);
  455.  
  456.     /* origin is with respect to ship2 */
  457.  
  458.     org_x = s2_x;
  459.     org_y = s2_y;
  460.  
  461.     /* Draw ship 2 */
  462.     drawgfx(ship2_vid,
  463.             Machine->gfx[10+((s2_sprite&0x04)>>2)],
  464.             (s2_sprite&0x03)^0x03,
  465.             0,
  466.             (s2_sprite&0x08)>>3,(s2_sprite&0x10)>>4,
  467.             s2_x-org_x,s2_y-org_y,
  468.             &clip,
  469.             TRANSPARENCY_NONE,
  470.             0);
  471.  
  472.     if (p1_sprite & 0x08)    /* if p1 is a projectile */
  473.     {
  474.         /* Draw projectile 1 */
  475.         drawgfx(proj1_vid,
  476.                 Machine->gfx[(p1_sprite&0x0c)>>2],
  477.                 (p1_sprite&0x03)^0x03,
  478.                 0,
  479.                 0,0,
  480.                 p1_x-org_x,p1_y-org_y,
  481.                 &clip,
  482.                 TRANSPARENCY_NONE,
  483.                 0);
  484.     }
  485.  
  486.     if (p2_sprite & 0x08)    /* if p2 is a projectile */
  487.     {
  488.         /* Draw projectile 2 */
  489.         drawgfx(proj2_vid,
  490.                 Machine->gfx[4+((p2_sprite&0x0c)>>2)],
  491.                 (p2_sprite&0x03)^0x03,
  492.                 0,
  493.                 0,0,
  494.                 p2_x-org_x,p2_y-org_y,
  495.                 &clip,
  496.                 TRANSPARENCY_NONE,
  497.                 0);
  498.     }
  499.  
  500.     /* Now check for collisions */
  501.     for (sy=0;sy<16;sy++)
  502.     {
  503.         for (sx=0;sx<16;sx++)
  504.         {
  505.             if (read_pixel(ship2_vid, sx, sy)==Machine->pens[1])
  506.                {
  507.                 /* Condition 1 - ship 2 = proj 1 */
  508.                 if (read_pixel(proj1_vid, sx, sy)==Machine->pens[1])
  509.                     return 1;
  510.                 /* Condition 2 - ship 2 = proj 2 */
  511.                 if (read_pixel(proj2_vid, sx, sy)==Machine->pens[1])
  512.                     return 1;
  513.             }
  514.         }
  515.     }
  516.  
  517.     return 0;
  518. }
  519.  
  520. void starcrus_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  521. {
  522.     fillbitmap(bitmap,Machine->pens[0],&Machine->drv->visible_area);
  523.  
  524.     /* Draw ship 1 */
  525.     drawgfx(bitmap,
  526.             Machine->gfx[8+((s1_sprite&0x04)>>2)],
  527.             (s1_sprite&0x03)^0x03,
  528.             0,
  529.             (s1_sprite&0x08)>>3,(s1_sprite&0x10)>>4,
  530.             s1_x,s1_y,
  531.             &Machine->drv->visible_area,
  532.             TRANSPARENCY_PEN,
  533.             0);
  534.  
  535.     /* Draw ship 2 */
  536.     drawgfx(bitmap,
  537.             Machine->gfx[10+((s2_sprite&0x04)>>2)],
  538.             (s2_sprite&0x03)^0x03,
  539.             0,
  540.             (s2_sprite&0x08)>>3,(s2_sprite&0x10)>>4,
  541.             s2_x,s2_y,
  542.             &Machine->drv->visible_area,
  543.             TRANSPARENCY_PEN,
  544.             0);
  545.  
  546.     /* Draw score/projectile 1 */
  547.     drawgfx(bitmap,
  548.             Machine->gfx[(p1_sprite&0x0c)>>2],
  549.             (p1_sprite&0x03)^0x03,
  550.             0,
  551.             0,0,
  552.             p1_x,p1_y,
  553.             &Machine->drv->visible_area,
  554.             TRANSPARENCY_PEN,
  555.             0);
  556.  
  557.     /* Draw score/projectile 2 */
  558.     drawgfx(bitmap,
  559.             Machine->gfx[4+((p2_sprite&0x0c)>>2)],
  560.             (p2_sprite&0x03)^0x03,
  561.             0,
  562.             0,0,
  563.             p2_x,p2_y,
  564.             &Machine->drv->visible_area,
  565.             TRANSPARENCY_PEN,
  566.             0);
  567.  
  568.     /* Collision detection */
  569.  
  570.     collision_reg = 0x00;
  571.  
  572.     /* Check for collisions between ship1 and ship2 */
  573.     if (starcrus_collision_check_s1s2())
  574.     {
  575.         collision_reg |= 0x08;
  576.     }
  577.     /* Check for collisions between ship1 and projectiles */
  578.     if (starcrus_collision_check_s1p1p2())
  579.     {
  580.         collision_reg |= 0x02;
  581.     }
  582.     /* Check for collisions between ship1 and projectiles */
  583.     if (starcrus_collision_check_s2p1p2())
  584.     {
  585.         collision_reg |= 0x01;
  586.     }
  587.     /* Check for collisions between ship1 and projectiles */
  588.     /* Note: I don't think this is used by the game */
  589.     if (starcrus_collision_check_p1p2())
  590.     {
  591.         collision_reg |= 0x04;
  592.     }
  593.  
  594. }
  595.  
  596. READ_HANDLER( starcrus_coll_det_r )
  597. {
  598.     return collision_reg ^ 0xff;
  599. }
  600.